﻿using GUI.RLAServiceReference;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GUI
{
    /// <summary>
    /// Interaction logic for UILogin.xaml
    /// Author: Anders^2
    /// </summary>
    public partial class UILogin : Window
    {
        private IRealLifeService _service;

        public UILogin()
        {
            _service = new RealLifeServiceClient();
            InitializeComponent();
        }

        private void btnOpretBruger_Click(object sender, RoutedEventArgs e)
        {
            UICreateUser uiCreateUser = new UICreateUser();
            uiCreateUser.Show();
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string email = txtEmail.Text;
            string password = txtPassword.Password;

            if (_service.ValidateLoginInformation(email, password) == 1)
            {
                User currentUser = _service.GetUser(email, password);

                OpenMainWindow(currentUser);
            }
            else
            {
                MessageBox.Show(string.Format("Fejl! Din fejl er {0}. \n Here is the following error possibilities: \n " +
                                              "-1: Ingen bruger med angivet email/password kombination blev ikke fundet \n" +
                                              "-2: Brugeren er blevet deaktiveret", _service.ValidateLoginInformation(email, password)));
            }
        }

        private void OpenMainWindow(User user)
        {
            UIMain uiMain = new UIMain(user);
            uiMain.Show();
            this.Close();
            //            throw new NotImplementedException("It's not part of this story!");
        }
    }
}